﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roguelike
{
    public enum tileType { empty, floor, wall, water, pit }

    public class TileManager
    {
        // key is the tile type; value is the Tile object representing that type of tile
        private Dictionary<tileType, Tile> tiles  = new Dictionary<tileType, Tile>();

        /// <summary>
        /// Constructor for TileManager
        /// </summary>
        public TileManager()
        {
            InitializeTiles();
        }

        /// <summary>
        /// Initializes tiles dictionary
        /// </summary>
        private void InitializeTiles()
        {
            // This will need to be refactored somehow when I introduce tile support
            tiles[tileType.empty] = new Tile(new Graphic(' '), new List<moveFlag>() { });
            tiles[tileType.floor] = new Tile(new Graphic('.'), new List<moveFlag>() { moveFlag.walk, moveFlag.fly });
            tiles[tileType.wall]  = new Tile(new Graphic('#'), new List<moveFlag>() { });
            tiles[tileType.water] = new Tile(new Graphic('~'), new List<moveFlag>() { moveFlag.swim, moveFlag.fly });
            tiles[tileType.pit]   = new Tile(new Graphic('v'), new List<moveFlag>() { moveFlag.fly });
        }

        /// <summary>
        /// Gets the passability flags associated with a tile type
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public List<moveFlag> GetTilePassFlags(tileType tile)
        {
            return tiles[tile].passFlags;
        }

        /// <summary>
        /// Get passability flags at x, y coordinates
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public List<moveFlag> GetXYPassFlags(int x, int y)
        {
            return GetTilePassFlags(Singleton<ScreenManager>.instance.GetTile(x, y));
        }

        /// <summary>
        /// Gets the Graphic for a specific type of tile
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public Graphic GetTileGraphic(tileType tile)
        {
            return tiles[tile].graphic;
        }

        /// <summary>
        /// Gets the textGraphic at x, y coordinates
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public char GetTextGraphic(int x, int y)
        {
            return tiles[Singleton<ScreenManager>.instance.GetTile(x,y)].graphic.textGraphic;
        }
    }
}
